package handle

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"video/api/basic/config"
	__ "video/api/basic/proto"
	"video/api/request"
)

func VideoAdd(c *gin.Context) {
	var req request.VideoAddReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"mag":  "参数验证失败",
			"data": err.Error(),
		})
		return
	}
	r, err := config.Client.VideoAdd(c, &__.VideoAddReq{
		UserId:   req.UserId,
		Title:    req.Title,
		Video:    req.Video,
		Describe: req.Describe,
		Category: req.Category,
	})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"mag":  "视频添加失败",
			"data": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"mag":  "视频添加成功",
		"data": r,
	})

}

func VideoModify(c *gin.Context) {
	var req request.VideoModifyReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"mag":  "参数验证失败",
			"data": err.Error(),
		})
		return
	}
	r, err := config.Client.VideoModify(c, &__.VideoModifyReq{
		Id:    int64(req.Id),
		State: int64(req.State),
	})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"mag":  "修改失败",
			"data": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"mag":  "修改成功",
		"data": r,
	})

}

func VideoList(c *gin.Context) {
	var req request.VideoListReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"mag":  "参数验证失败",
			"data": err.Error(),
		})
		return
	}
	r, err := config.Client.VideoList(c, &__.VideoListReq{
		Upper: req.Upper,
		Below: req.Below,
	})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"mag":  "列表展示失败",
			"data": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"mag":  "列表展示成功",
		"data": r,
	})
}
